# vim: ts=4:sw=4:syntax=perl

use gri_secmgr qw(get_user_name);
# CSS-V1

sub mm_users_requests_summary_list($) {
my $order_by=shift;

	my $req_dir=$::GRI_FRONTEND->get_directory("requests");
	my $rdb=new gri2_requests("$req_dir/requests.db");
	my ($rc,$str);
	if(!defined($rdb)) {
		($rc,$str)=gri2_requests::error();
		return html_error("Failed to open requests database: $str",1);
	}
	# Grab the request information first before worrying about sorting this stuff.
	my $open_requests=$rdb->get_my_requests({user=>get_user_name()});

	# Sort any records first

	# Plop the records in the table now...

	my $s=""; my $row=0;
	for my $_crec (@{$open_requests->{records}}) {
		my $crec=$rdb->decode($_crec);
		my $class="gri_odd";
		$class="gri_even" if $row%2==0;
		my $status="??";
		if(defined($crec->{decision}) && length($crec->{decision})) {
			$status=$crec->{decision};
		}
		$s.="<tr id=$class><td class=gri_cell>$crec->{id}</td>";
		my $xx=$::GRI_FRONTEND->datetime_str($crec->{raised});
		$s.="<td class=gri_cell>$xx</td>";
		$s.="<td class=gri_cell>$status</td>";
		# Updated is the utime of the last update (or when closed if closed)
		my $updated=$crec->{decision_time};
		if($updated==0) {
			$updated='&nbsp;';
		} else {
			$updated=$::GRI_FRONTEND->datetime_str($updated);
		}
		$s.="<td class=gri_cell>$updated</td>";
		# A link to view more details...
		my $link=my $l=link_to_str("stdlink","Details","users_requests_detail_page","id=$crec->{id}");
		$s.="<td class=gri_cell-right>$link</td></tr>\n";
		$row++;
	}
	return $s;
}


